package net.kunyv.base.controller;

import net.kunyv.base.entity.SysUser;
import net.kunyv.base.service.SysUserService;
import net.kunyv.log.ActLog;
import net.kunyv.log.OperType;
import net.kunyv.util.PageParam;
import net.kunyv.util.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author sunyb
 * @create 2017-08-02 15:57
 */
@Controller
@RequestMapping(value = "/SysUser")
public class SysUserController {
    Logger logger = LoggerFactory.getLogger(SysUserController.class);
    @Autowired
    private SysUserService sysUserService;


    /**
     * 跳转用户管理界面
     *
     * @return
     * @author sunyb
     * @date 2018-12-7
     */
    @RequestMapping(method = RequestMethod.GET, value = "/query")
    public String getRole() {
        return "login/system/sys_user";
    }


    /**
     * 获取用户列表
     *
     * @return
     * @author sunyb
     * @date 2020-08-28
     */
    @ResponseBody
    @ActLog(value = "查询用户", type = OperType.QUERY)
    @RequestMapping(method = RequestMethod.GET, value = "/getUser")
    public PageResult getUser(String userName, PageParam pageParam) {
        return sysUserService.getUserList(userName, pageParam);
    }


    /**
     * 保存用户
     *
     * @return
     * @author sunyb
     * @date 2020-08-28
     */
    @ResponseBody
    @ActLog(value = "保存用户", type = OperType.AddOrUpdate)
    @RequestMapping(value = "/saveUser")
    public String saveUser(SysUser sysUser) {
        return sysUserService.saveUser(sysUser);
    }

    /**
     * 删除用户
     *
     * @param userId
     * @return java.lang.String
     * @throw
     * @author sunyb
     * @date 2020-08-28
     */
    @ResponseBody
    @ActLog(value = "删除用户", type = OperType.DELETE)
    @RequestMapping(value = "/deleteUserByUserId")
    public String deleteUserByUserId(String userId) {
        return sysUserService.deleteUserByUserId(userId);
    }

}
